package com.bnz.service.impl;

import com.bnz.dao.UserDao;
import com.bnz.pojo.User;
import com.bnz.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;


    //1. 开始转换
    @Override
    public void trans(int idOut, int idIn, double balance) {
        //1.1 转出
        userDao.updateUser(idOut,-balance);
        //1.2 转入
        userDao.updateUser(idIn,balance);
    }

    /**
     * 2. 添加用户
     * @param user
     */
    @Override
    public void add(User user) {
        userDao.add(user);
    }

    /**
     * 3. 根据id查询用户
     * @param id
     * @return
     */
    @Override
    public User findById(int id) {
        return userDao.findById(id);
    }

    /**
     * 4. 修改用户信息
     * @param user
     */
    @Override
    public void update(User user) {
        userDao.update(user);
    }

    @Override
    public void delete(User user) {
        userDao.delete(user);
    }

}
